<template>
	<view class="">
		<!--  -->
		<ben></ben>
		<!--  -->
		<!-- <view class="background_f">
			<uni-segmented-control :current="current" :values="tabList" @clickItem="onClickItem" styleType="text"
				activeColor="#FFAD4C"></uni-segmented-control>
				v-if="type != 'store'"
		</view> -->
		<view class="row min30_rl padtop20 just_cont_spacebet">
			<view class="col0 size28 font500 row align_item_c">
				可提现积分
				<view class="size36 font600" style="color: #FE3C3C;">
					{{ user_type == 3 ? userinfo.salesman_money : userinfo.shop_money }}
				</view>
			</view>
			<view class="size28 font500 row align_item_b" style="color: #FE9110;"
				@click="$jump.nav('/indexpackage/store/cashout_records')">
				提现记录
				<u-icon name="arrow-right" color="#FE9110" size="13"></u-icon>
			</view>
		</view>
		<view class="column min30 rad1 pad30 background_f">
			<view class="row min20_tb size36 font600 col0" style="align-items: flex-end;">
				{{ current == 0 ? '提现积分' : '提现金额' }}
				<view class="size24 font500 minleft10" style="color: #FE3C3C;">
					{{ current == 0 ? '可提现积分：' : '可提现金额：￥' }}{{ user_type == 3 ? userinfo.salesman_money : userinfo.shop_money }}
				</view>
			</view>
			<view class="row">
				<!-- #ifndef APP-NVUE -->
				<u-input placeholder="请输入积分数量" v-model="integral" border="bottom" clearable>
				<!-- #endif -->
					<!-- #ifdef APP-NVUE -->
					<u--input placeholder="请输入积分数量" v-model="integral" border="bottom" clearable>
					<!-- #endif -->
						<u--text text="￥" slot="prefix" bold="true" size="20" color="#000"></u--text>
				<!-- #ifndef APP-NVUE -->
				</u-input>
				<!-- #endif -->
				<!-- #ifdef APP-NVUE -->
				</u--input>
				<!-- #endif -->
			</view>
			<!-- <view class="row" v-else> -->
			<!-- #ifndef APP-NVUE -->
			<!-- <u-input placeholder="请输入提现金额" v-model="money" border="bottom" clearable>  v-if="current == 0"-->
			<!-- #endif -->
			<!-- #ifdef APP-NVUE -->
			<!-- <u--input placeholder="请输入提现金额" v-model="money" border="bottom" clearable> -->
			<!-- #endif -->
			<!-- <u--text text="￥" slot="prefix" bold="true" size="20" color="#000"></u--text> -->
			<!-- #ifndef APP-NVUE -->
			<!-- </u-input> -->
			<!-- #endif -->
			<!-- #ifdef APP-NVUE -->
			<!-- </u--input> -->
			<!-- #endif -->
			<!-- </view> -->
			<view class="box size22 font500">
				提示：提现审核预计1~7个工作日
			</view>
		</view>
		<view class="column min30 rad1 pad30 background_f" style="margin-top: 0;">
			<view class="size30 font600 col0">
				选择提现银行卡
			</view>
			<view class="" v-if="bank_list">
				<u-radio-group v-model="radiovalue1" placement="column" iconPlacement="right" activeColor="#FFAD4C">
					<u-radio :customStyle="{marginTop: '15px',paddingBottom: '10px',borderBottom: '1px solid #f1f1f1'}"
						v-for="(bank_item,bank_index) in bank_list" :key="bank_index" :label="bank_item.bank"
						:name="bank_item.id" labelSize="15">
					</u-radio>
				</u-radio-group>
			</view>
			<view class="mintop40 disflex just_cont_c size26" style="color: #FF7400;align-items: baseline;"
				@click="$jump.nav('/mypackage/store/add_bankcard')">
				添加其他银行卡
				<u-icon name="arrow-right" color="#FF7400" size="13"></u-icon>
			</view>
		</view>
		<!-- <view class="pad30_rl mintop20">
			<view class="text_center size28 font600" style="color: #7B7F88;">
				{{ current == 0 ? '积分提现说明' : '余额提现说明' }}
			</view>
			<view class="mintop20">
				12123123123123
			</view>
		</view> -->
		<view class="mintop40 minbottom20 col9 size22 font500 row just_cont_c align_item_c">
			<checkbox :checked="checked" style="transform:scale(0.7)"
				@click="checked = checked == false ? true : false" />
			我已阅读并同意
			<view style="color: #FE3C3C;" @click="$jump.nav('/indexpackage/web/protocol?type=' + 'payout_agreement')">
				《提现协议》
			</view>
		</view>
		<view style="margin: auto 60rpx;">
			<u-button text="确认提现" shape="circle" color="#FFAD4C" hairline="false" size="normal"
				@click="getPayouts"></u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user_id: '',
				user_type: '',
				userinfo: {},
				page: 0,
				type: '123',
				tabList: ['积分提现', '余额提现'],
				current: 0,
				totalmoney: '999',
				totalintegral: '666',
				money: '',
				integral: '',
				checked: false,
				bank_list: [],
				radiovalue1: '',
			}
		},
		onShow() {
			this.user_type = uni.getStorageSync('user_type');
			//当前页面展示的时候他就执行该生命周期
			this.user_id = uni.getStorageSync('user_id');
			const token = uni.getStorageSync('token');
			if (token) {
				//如果存在token
				this.getUserinfo()
				this.getBankList()
				//按正常逻辑来讲 登录成功 我们是不是需要向服务器获取用户的信息？
				//那么我们一起来获取用户信息
			} else {

				uni.showToast({
					title: '您还未登录，正在前往登录',
					icon: 'none'
				})
				setTimeout(function() {
					uni.navigateTo({
						url: "/mypackage/user/login"
					})
				}, 1000)
			}
		},
		methods: {
			onClickItem(e) {
				if (this.current != e.currentIndex) {
					this.current = e.currentIndex;
				}
			},
			async getPayouts() {
				if (!this.integral) {
					uni.showToast({
						title: '填写提现积分数',
						icon: 'none'
					})
					return
				}
				if (!this.radiovalue1) {
					uni.showToast({
						title: '请选择银行卡',
						icon: 'none'
					})
					return
				}
				console.log(this.checked);
				if (this.checked == false) {
					uni.showToast({
						title: '请同意提现协议！',
						icon: 'none'
					})
					return
				}
				var info = {
					score: this.integral,
					bank_id: this.radiovalue1
				}
				if (this.user_type == 3) {
					info['user_id'] = this.user_id
				}
				if (this.user_type == 2) {
					info['shop_id'] = this.user_id
				}
				let {
					code,
					message,
					data
				} = await this.$com.fetch("shop/payouts", info)
				if (code == 200) {
					uni.showToast({
						title: message,
						icon: 'success'
					})
					this.integral = ''
					this.getUserinfo()
				} else {
					console.log(message);
				}
			},
			async getUserinfo() {
				let {
					code,
					message,
					data
				} = await this.$com.fetchGet("member/user_info/" + this.user_id)
				if (code == 200) {
					this.userinfo = data

				} else {
					console.log(message);
				}
			},
			async getBankList() {
				this.page++
				let {
					code,
					message,
					data
				} = await this.$com.fetchGet("member/bank_cards_list/" + this.user_id, {
					page: this.page,
				})
				if (code == 200) {
					this.bank_list.push(...data.items)
					this.radiovalue1 = this.bank_list[0].id
					if (data.items.length == 0) {
						return
					} else {
						this.getBankList()
					}
				} else {
					console.log(message);
				}
			},
		}
	}
</script>

<style scoped lang="less">
	.box {
		background-color: #FBF7F4;
		padding: 16rpx 0;
		padding-left: 40rpx;
		color: #B49588;
	}
</style>